/* USER CODE BEGIN Header */
/**
  ******************************************************************************
  * File Name          : freertos.c
  * Description        : Code for freertos applications
  ******************************************************************************
  * @attention
  *
  * Copyright (c) 2024 STMicroelectronics.
  * All rights reserved.
  *
  * This software is licensed under terms that can be found in the LICENSE file
  * in the root directory of this software component.
  * If no LICENSE file comes with this software, it is provided AS-IS.
  *
  ******************************************************************************
  */
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "FreeRTOS.h"
#include "task.h"
#include "main.h"
#include "cmsis_os.h"

/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
#include "lvgl.h"
#include "lv_port_disp.h"
#include "lv_port_indev.h"
#include "lv_port_fs.h"
/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
typedef StaticTask_t osStaticThreadDef_t;
typedef StaticSemaphore_t osStaticMutexDef_t;
/* USER CODE BEGIN PTD */

/* USER CODE END PTD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */

/* USER CODE END PD */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */

/* USER CODE END PM */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN Variables */

/* USER CODE END Variables */
/* Definitions for LvglTask */
osThreadId_t LvglTaskHandle;
uint32_t LvglTaskBuffer[ 1024 ];
osStaticThreadDef_t LvglTaskControlBlock;
const osThreadAttr_t LvglTask_attributes = {
  .name = "LvglTask",
  .cb_mem = &LvglTaskControlBlock,
  .cb_size = sizeof(LvglTaskControlBlock),
  .stack_mem = &LvglTaskBuffer[0],
  .stack_size = sizeof(LvglTaskBuffer),
  .priority = (osPriority_t) osPriorityLow7,
};
/* Definitions for TouchScanTask */
osThreadId_t TouchScanTaskHandle;
uint32_t TouchScanTaskBuffer[ 128 ];
osStaticThreadDef_t TouchScanTaskControlBlock;
const osThreadAttr_t TouchScanTask_attributes = {
  .name = "TouchScanTask",
  .cb_mem = &TouchScanTaskControlBlock,
  .cb_size = sizeof(TouchScanTaskControlBlock),
  .stack_mem = &TouchScanTaskBuffer[0],
  .stack_size = sizeof(TouchScanTaskBuffer),
  .priority = (osPriority_t) osPriorityLow,
};
/* Definitions for LvglMutex */
osMutexId_t LvglMutexHandle;
osStaticMutexDef_t LvglMutexControlBlock;
const osMutexAttr_t LvglMutex_attributes = {
  .name = "LvglMutex",
  .cb_mem = &LvglMutexControlBlock,
  .cb_size = sizeof(LvglMutexControlBlock),
};

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN FunctionPrototypes */

/* USER CODE END FunctionPrototypes */

void StartLvglTask(void *argument);
void StartTouchScanTask(void *argument);

void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */

/**
  * @brief  FreeRTOS initialization
  * @param  None
  * @retval None
  */
void MX_FREERTOS_Init(void) {
  /* USER CODE BEGIN Init */
  lv_init();                  /* lvgl init */
  lv_port_disp_init();        /* lvgl 显示接口初始化，放到 lv_init() 之后 */
  lv_port_indev_init();       /* lvgl 输入接口初始化，放到 lv_init() 之后 */
  lv_port_fs_init();          /* lvgl 输入接口初始化，放到 lv_init() 之后 */
  /* USER CODE END Init */
  /* Create the mutex(es) */
  /* creation of LvglMutex */
  LvglMutexHandle = osMutexNew(&LvglMutex_attributes);

  /* USER CODE BEGIN RTOS_MUTEX */
  /* add mutexes, ... */
  /* USER CODE END RTOS_MUTEX */

  /* USER CODE BEGIN RTOS_SEMAPHORES */
  /* add semaphores, ... */
  /* USER CODE END RTOS_SEMAPHORES */

  /* USER CODE BEGIN RTOS_TIMERS */
  /* start timers, add new ones, ... */
  /* USER CODE END RTOS_TIMERS */

  /* USER CODE BEGIN RTOS_QUEUES */
  /* add queues, ... */
  /* USER CODE END RTOS_QUEUES */

  /* Create the thread(s) */
  /* creation of LvglTask */
  LvglTaskHandle = osThreadNew(StartLvglTask, NULL, &LvglTask_attributes);

  /* creation of TouchScanTask */
  TouchScanTaskHandle = osThreadNew(StartTouchScanTask, NULL, &TouchScanTask_attributes);

  /* USER CODE BEGIN RTOS_THREADS */
  /* add threads, ... */
  /* USER CODE END RTOS_THREADS */

  /* USER CODE BEGIN RTOS_EVENTS */
  /* add events, ... */
  /* USER CODE END RTOS_EVENTS */

}

/* USER CODE BEGIN Header_StartLvglTask */
/**
  * @brief  Function implementing the LvglTask thread.
  * @param  argument: Not used
  * @retval None
  */
/* USER CODE END Header_StartLvglTask */
__weak void StartLvglTask(void *argument)
{
  /* USER CODE BEGIN StartLvglTask */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END StartLvglTask */
}

/* USER CODE BEGIN Header_StartTouchScanTask */
/**
* @brief Function implementing the TouchScanTask thread.
* @param argument: Not used
* @retval None
*/
/* USER CODE END Header_StartTouchScanTask */
__weak void StartTouchScanTask(void *argument)
{
  /* USER CODE BEGIN StartTouchScanTask */
  /* Infinite loop */
  for(;;)
  {
    osDelay(1);
  }
  /* USER CODE END StartTouchScanTask */
}

/* Private application code --------------------------------------------------*/
/* USER CODE BEGIN Application */

/* USER CODE END Application */

